
package com.kweative.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author henrik
 */
public class StringUtil {
    public static String firstToUpper(String string) {
        return string.substring(0,1).toUpperCase() + string.substring(1);
    }
    public static String GUID() {
        return GUID(null);
    }
    public static String GUID(Object spice) {
        try {
            Date d = new Date();
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.reset();
            String id = String.valueOf(d.getTime());
            if (spice != null)
                id += String.valueOf(spice);
            md.update(id.getBytes());
            byte messageDigest[] = md.digest();
            
            StringBuilder hexString = new StringBuilder();
            for (int i=0;i<messageDigest.length;i++) {
                hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(StringUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
